/*package linpeng.ztb;

import java.util.ArrayList;

import linpeng.service.WebService;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Window;
import android.widget.ImageView;

public class PicDetail extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.pic_detail);
		Intent intent = getIntent();
		ArrayList<String> urls = intent.getStringArrayListExtra("picurl");
		System.out.println(urls.size());
		
		byte[] PicData=WebService.getImage(url);
		Bitmap bit = BitmapFactory.decodeByteArray(PicData, 0,PicData.length);
		
		ImageView ImageBig = (ImageView) findViewById(R.id.picdetail);
		ImageBig.setImageBitmap(bit);
	}
}
*/

package linpeng.ztb;

import java.util.ArrayList;

import linpeng.service.WebService;
import android.R.layout;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter;
import android.widget.SpinnerAdapter;
import android.widget.Toast;
import android.widget.AdapterView.AdapterContextMenuInfo;


public class PicDetail extends Activity {
 private Gallery gallery;
 private Gallery gallery1;

 /*
  * (non-Javadoc)
  * 
  * @see android.app.Activity#onCreate(android.os.Bundle)
  */
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.pic_detail);
  gallery = (Gallery) findViewById(R.id.gallery);
  
  Intent intent = getIntent();
  ArrayList<String> urls = intent.getStringArrayListExtra("picurl");
	System.out.println(urls.size());
	gallery.setAdapter(new ImageAdapter(this,urls));
  registerForContextMenu(gallery);
 
        
 }

 public class ImageAdapter extends BaseAdapter{
  int mGalleryItemBackground;
  private Context mContext;

 
  private ArrayList<String> picurls;
  private Integer[]  mImageIds;
  public ImageAdapter(Context context,ArrayList<String> picurls) {
   mContext = context;
   this.picurls=picurls;
   mImageIds=new Integer[picurls.size()];
   TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
   mGalleryItemBackground = a.getResourceId(
     R.styleable.Gallery1_android_galleryItemBackground, 0);
   a.recycle();
  }

  public int getCount() {
	 
	 
   return mImageIds.length;
  }

  
  public Object getItem(int position) {
   return position;
  }

  
  public long getItemId(int position) {
   return position;
  }

  
  public View getView(int position, View convertView, ViewGroup parent) {
   ImageView i = new ImageView(mContext);
   byte[] PicData=WebService.getImage(picurls.get(position));
	Bitmap bit = BitmapFactory.decodeByteArray(PicData, 0,PicData.length);
   i.setImageBitmap(bit);
  //i.setImageResource(mImageIds[position]);
   i.setScaleType(ImageView.ScaleType.FIT_XY);
   i.setLayoutParams(new Gallery.LayoutParams(800, 1000));

   // The preferred Gallery item background
   i.setBackgroundResource(mGalleryItemBackground);

   return i;
  }

 }


}

